package Controllers;

import java.awt.Point;
import java.awt.event.MouseEvent;
import java.awt.event.MouseListener;
import java.awt.event.MouseMotionListener;

import GUI.ConnectionFrame;

/**
 * Class implementing the listener interfaces for handling events.
 * Responsible for listening to events pertaining a {@link ConnectionFrame}.
 * 
 * @author Danny Johansen, Didzis Petkus, Liviu Berheci.
 *
 */
public class ConnectionFrameListener implements MouseListener,
		MouseMotionListener {

	private Controller parent;
	private Point mapStartDrag;
	private ConnectionFrame frame;
	private Point beforeDragCenter;

	/**
	 * Constructor stating the main controller and the target frame
	 * to listen to events from.
	 * @param main - the passed main(parent) {@link Controller} object.
	 * @param frame - the passed {@link ConnectionFrame} object.
	 */
	public ConnectionFrameListener(Controller main, ConnectionFrame frame) {
		this.parent = main;
		this.frame = frame;
	}

	@Override
	public void mousePressed(MouseEvent e) {
		beforeDragCenter = frame.copyCenter();
		mapStartDrag = new Point(e.getX(), e.getY());
	}

	@Override
	public void mouseDragged(MouseEvent e) {
		if (mapStartDrag != null && beforeDragCenter != null) {
			int newX = (int) (beforeDragCenter.getX() + (e.getX() - mapStartDrag
					.getX()));
			int newY = (int) (beforeDragCenter.getY() + (e.getY() - mapStartDrag
					.getY()));
			frame.updateCenter(new Point(newX, newY));
		}

	}

	@Override
	public void mouseMoved(MouseEvent e) {
		// TODO Auto-generated method stub

	}

	@Override
	public void mouseClicked(MouseEvent e) {
		// TODO Auto-generated method stub

	}

	@Override
	public void mouseEntered(MouseEvent e) {
		// TODO Auto-generated method stub

	}

	@Override
	public void mouseExited(MouseEvent e) {
		// TODO Auto-generated method stub

	}

	@Override
	public void mouseReleased(MouseEvent e) {
		// TODO Auto-generated method stub

	}

}
